home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.7 KB | 245 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLPriStr.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef SLPRIDEB_H
- #include "SLPriDeb.h"
- #endif
-
- #ifndef SLPRISTR_H
- #include "SLPriStr.h"
- #endif
-
- #ifndef SLPRIMEM_H
- #include "SLPriMem.h"
- #endif
-
- #ifdef FW_BUILD_MAC
- #include <Memory.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWCommon
- #endif
-
- #ifndef FW_USE_STANDARD_LIBRARY
- #define FW_USE_STANDARD_LIBRARY 1
- #endif
-
- #if FW_USE_STANDARD_LIBRARY
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringLength
- //----------------------------------------------------------------------------------------
-
- size_t FW_PrimitiveStringLength(const char * p)
- {
- // No try block necessary - Do not throw
- FW_PRIV_ASSERT(p != 0);
- #if FW_USE_STANDARD_LIBRARY
- return strlen(p);
- #else
- size_t i = 0;
- for (; *p; p++, i++) ;
- return i;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_PrimitiveStringEqual(const char *p1, const char *p2)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- return strcmp(p1,p2)==0;
- #else
- while (true)
- {
- char c1 = *p1++;
- char c2 = *p2++;
-
- if (c1 != c2)
- return false;
-
- if (!c1)
- return true;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringEqual
- //----------------------------------------------------------------------------------------
-
- int FW_PrimitiveStringCompare(const char *p1, const char *p2)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- return strcmp(p1,p2);
- #else
- int result = 0; // assume strings are equal
-
- const unsigned char* s1 = (const unsigned char*) p1;
- const unsigned char* s2 = (const unsigned char*) p2;
-
- unsigned char c1 = 0;
- unsigned char c2 = 0;
-
- while (true)
- {
- c1 = *s1++;
- c2 = *s2++;
- if (!c1)
- break;
- if (c1 != c2)
- break;
- }
-
- if (c1 < c2)
- result = -1;
- if (c1 > c2)
- result = 1;
-
- return result;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringCopy
- //----------------------------------------------------------------------------------------
-
- void FW_PrimitiveStringCopy(const char *source, char *destination)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- strcpy(destination, source);
- #else
- char c;
-
- while ((c = *source++) != '\0')
- *destination++ = c;
-
- *destination = '\0';
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringDuplicate
- //----------------------------------------------------------------------------------------
- // Added by HLX
-
- char* FW_PrimitiveStringDuplicate(const char *source)
- {
- // No try block necessary - Do not throw
- char* destination = (char*)FW_PrimitiveAllocateBlock(FW_PrimitiveStringLength(source) + 1);
- if (destination)
- FW_PrimitiveStringCopy(source, destination);
- return destination;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringCatenate
- //----------------------------------------------------------------------------------------
-
- void FW_PrimitiveStringCatenate(const char *source, char *destination)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- strcat(destination, source);
- #else
- size_t len = FW_PrimitiveStringLength(destination);
- FW_PrimitiveStringCopy(source, destination+len);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveStringFindCharacter
- //----------------------------------------------------------------------------------------
-
- char * FW_PrimitiveStringFindCharacter(const char *source, char c)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- return strchr(source, c);
- #else
- while (1)
- {
- char cc;
- if (c == (cc = *source))
- {
- return (char *) source;
- }
- else if (!cc)
- {
- return NULL;
- }
- else
- source++;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveCharacterToUpper
- //----------------------------------------------------------------------------------------
-
- char FW_PrimitiveCharacterToUpper(char c)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- return toupper(c);
- #else
- if (c >= 'a' && c <= 'z')
- return (c - 'a' + 'A');
- else
- return (c);
- #endif
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveCharacterToLower
- //----------------------------------------------------------------------------------------
-
- char FW_PrimitiveCharacterToLower(char c)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- return tolower(c);
- #else
- if (c >= 'A' && c <= 'Z')
- return (c + 'a' - 'A');
- else
- return (c);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveCharacterIsSpace
- //----------------------------------------------------------------------------------------
-
- char FW_PrimitiveCharacterIsSpace(char c)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- return isspace(c);
- #else
- return ((c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f') ? c : 0);
- #endif
- }
-
-
-